package edu.drexel.cs544.group11.common;

import java.io.IOException;
import java.io.PrintStream;

/**
 * Defines functionality common to all types of messages in BSP
 * 
 * CS 544
 * 
 * @author Group 11:
 * @author Jason Setzer
 * @author Tam Thongsima
 * @author Kenny Oyefara
 * @author Chase Miller
 * 
 * @date Spring 2013
 * 
 */
public abstract class MessageBase {
    
    public static final String separator = ";";
    protected final String emptyIndicator = "*empty*";
    
    /**
     * Sends a message over the specified PrintStream
     * 
     * @param stream
     * @throws IOException
     * @throws MessageFormatException
     */
    public abstract void sendMessage(PrintStream stream) throws IOException, MessageFormatException;
    
    /**
     * Logic to detect if this message is malformed (i.e. is missing stuff we
     * defined in the PDU)
     * 
     * @return
     */
    public abstract boolean isMalformedMessage();
    
    /**
     * Formats this message for transmission over the network.
     */
    protected abstract String formatForProtocolTransmission();
    
    public static String getEndOfMessage() {
	return ";;\n";
    }
    
}
